using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Keep.Const;
using Keep.Model;
using Keep.Service;
using Microsoft.AspNetCore.Mvc;
using Serilog;

namespace Keep.Controllers;

[ApiController]
[Route("api/[controller]/[action]")]
public class MusicOfListController : ControllerBase
{
    private readonly IMusicListService musicListService;
    private readonly IMusicOfListService musicOfListService;

    public MusicOfListController(IMusicListService musicListService, IMusicOfListService musicOfListService)
    {
        this.musicListService = musicListService;
        this.musicOfListService = musicOfListService;
    }

    [HttpPost(Name = "GetMusicOfList")]
    public async Task<ActionResult<ResultData>> GetMusicOfList()
    {
        Log.Warning("IN");
        List<MusicList> sys = await Task.Run(() => musicOfListService.SelMusicList());
        Log.Warning("OUT => " + sys.ToString() + "  数量:" + sys.Count);
        return Ok(new ResultData(Static.Enable, sys));
    }

    [HttpPost(Name = "GetMusicOfListBymlid")]
    public async Task<ActionResult<ResultData>> GetMusicOfListBymlid(MusicList musicList)
    {
        Log.Warning("IN");
        List<MusicOfList> sys = await Task.Run(() => musicOfListService.SelMusicListBymlid((int)musicList.id));
        Log.Warning("OUT => " + sys.ToString() + "  数量:" + sys.Count);
        return Ok(new ResultData(Static.Enable, sys));
    }

    [HttpPost(Name = "AddMusicOfList")]
    public async Task<ActionResult<ResultData>> AddMusicOfList(MusicOfList musicOfList)
    {
        Log.Warning("IN");
        bool sys = await Task.Run(() => musicOfListService.AddMusicOfList(musicOfList));
        Log.Warning("OUT => " + sys);
        return Ok(new ResultData(Static.Enable, sys));
    }
    //大概率废弃
    [HttpPost(Name = "EditMusicOfList")]
    public async Task<ActionResult<ResultData>> EditMusicOfList(MusicOfList musicOfList)
    {
        Log.Warning("IN");
        bool sys = await Task.Run(() => musicOfListService.EditMusicOfList(musicOfList));
        Log.Warning("OUT => " + sys);
        return Ok(new ResultData(Static.Enable, sys));
    }

    [HttpPost(Name = "DelMusicOfList")]
    public async Task<ActionResult<ResultData>> DelMusicOfList(MusicOfList musicOfList)
    {
        Log.Warning("IN");
        bool sys = await Task.Run(() => musicOfListService.DelMusicOfList((int)musicOfList.id));
        Log.Warning("OUT => " + sys);
        return Ok(new ResultData(Static.Enable, sys));
    }

}
